{include file="common/header"/}
<style>
  img {
    width: 100px;
    height: 100px;
  }
</style>
<div class="lemo-container">
  <div class="lemo-main">
      <div class="admin-main layui-anim layui-anim-upbit">
          <fieldset class="layui-elem-field layui-field-title">
              <legend>编辑客户报价表</legend>
          </fieldset>
      <form class="layui-form layui-form-pane" action="" lay-filter="form">
          <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
              <input type="text"  name="product_name" required  lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">实物图</label>
            <input type="hidden" name="physical_pic" id="physical_pic">
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary upload-btn" data-path="user" data-target="physical_pic" data-preview="addPic"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="addPic">
                        <p id="notice"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品规格图</label>
            <input type="hidden" name="specifications_pic" id="specifications_pic">
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary upload-btn" data-path="user" data-target="specifications_pic" data-preview="addPic1"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="addPic1">
                        <p id="notice"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品属性</label>
            <div class="layui-input-block">
              <input type="text"  name="attribute" required  lay-verify="required" placeholder="请输入商品属性" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-block">
              <input type="text"  name="unit" required  lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">报价截图</label>
            <input type="hidden" name="quotation_pic" id="quotation_pic">
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary upload-btn" data-path="user" data-target="quotation_pic" data-preview="addPic2"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="addPic2">
                        <p id="notice"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">调价日期</label>
          <div class="layui-input-block">
            <input type="text" name="price_adjustment_date" class="layui-input" id="ID-laydate-demo" placeholder="请选择日期">
          </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">拿货成本</label>
            <div class="layui-input-block">
              <input type="text"  name="purchasing_cost" required  lay-verify="required" placeholder="请输入拿货成本" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">耗材</label>
            <div class="layui-input-block">
              <input type="text"  name="consumables" required  lay-verify="required" placeholder="请输入耗材" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">人工</label>
            <div class="layui-input-block">
              <input type="text"  name="artificial" required  lay-verify="required" placeholder="请输入人工" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">货损</label>
            <div class="layui-input-block">
              <input type="text"  name="cargo_damage" required  lay-verify="required" placeholder="请输入货损" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">厂家</label>
            <div class="layui-input-block">
              <input type="text"  name="manufactor" required  lay-verify="required" placeholder="请输入厂家" autocomplete="off" class="layui-input">
            </div>
          </div>

          <div class="layui-form-item">
            <label class="layui-form-label">产品类型</label>
            <div class="layui-input-inline">
                <select name="product_type">
                    <option value="0"></option>
                    <option value="1">自营</option>
                    <option value="2">代发</option>
                </select>
            </div>
          </div>

          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
              <textarea name="notes" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
          </div>

          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">运费备注</label>
            <div class="layui-input-block">
              <textarea name="freight_remarks" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
          </div>

        <div class="layui-form-item">
          <div class="layui-input-inline">
              <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
              <a data-href="{:url('customer')}" class="layui-btn layui-btn-primary back">{:lang('back')}</a>
          </div>
      </div>
      <input type="hidden" name="id" value="{$id}">
        </form>
  </div>
  </div>
</div>
  {include file="common/footer"/}

<script>
  layui.config({
      base: '/static/admin/js/',
      version: true
  }).extend({
      Admin: 'Admin',
  }).use(['form','Admin', 'laydate', 'upload'], function () {
      var form = layui.form, 
          layer = layui.layer,
          $ = layui.jquery, 
          laydate = layui.laydate, 
          upload = layui.upload;
      

      var info = {:json_encode($info)};
      
      
        console.log(info);
        // form.val("form", info);
      if(info){
          $('#physical_pic').attr('src',info.physical_pic);
          $('#specifications_pic').attr('src',info.specifications_pic);
          $('#quotation_pic').attr('src',info.quotation_pic);

          $('#addPic').attr('src',info.physical_pic);
          $('#addPic1').attr('src',info.specifications_pic);
          $('#addPic2').attr('src',info.quotation_pic);
      }
      laydate.render({
        elem: '#ID-laydate-demo',
        type: 'date',
        value: new Date(),
      });
      form.render();
      form.val("form", info);
      // 统一处理所有上传按钮
      $('.upload-btn').each(function() {
          var $btn = $(this);
          var path = $btn.attr('data-path');
          var target = $btn.attr('data-target');
          var preview = $btn.attr('data-preview');
          
          upload.render({
              elem: $btn,
              url: '/admin/sys.uploads/uploads?path='+path,
              before: function(obj){
                  obj.preview(function(index, file, result){
                      $('#' + preview).attr('src', result);
                  });
              },
              done: function(res){
                  if(res.code>0){
                      $('#' + target).val(res.url);
                      return layer.msg('上传成功');
                  }else{
                      return layer.msg('上传失败');
                  }
              },
              error: function(){
                  var notice = $btn.siblings('.layui-upload-list').find('#notice');
                  notice.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                  notice.find('.demo-reload').on('click', function(){
                      uploadInt.upload();
                  });
              }
          });
      });
  });
</script>